home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / SourceCode / OOP_Course / Examples / DrawTests / Display / DisplayView.m < prev    next >
Text File  |  1992-12-19  |  2KB  |  70 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "DisplayView.h"
  5.  
  6. @implementation DisplayView
  7.  
  8. - initFrame:(const NXRect *)theFrame
  9. {
  10.     [super initFrame:theFrame];
  11.     sqSide=100.;                 //and length of a side
  12.     NXSetRect(&sqRect, bounds.size.width/2.0, bounds.size.height/2.0,3*sqSide,sqSide);
  13.     backgroundGray=NX_WHITE;
  14.     return self;
  15. }
  16.  
  17. - (float)backgroundGray
  18. {
  19.     return backgroundGray;
  20. }
  21.  
  22. - takeBackgroundGrayFrom:sender
  23. {
  24.     backgroundGray = [sender floatValue];
  25.     [self display];
  26.     return self;
  27. }
  28.  
  29. - drawSelf:(const NXRect *)r :(int)c
  30. {
  31.     // method is invoked everytime mouse is clicked in a different location
  32.      int    i, length = sqSide/8;
  33.      
  34.      /* Draw background */
  35.      PSsetgray(backgroundGray);
  36.      NXRectFill(&bounds);
  37.      /* Start drawing */
  38.      PSsetgray(NX_BLACK);
  39.      PSsetlinewidth(5.0);
  40.  
  41.     PSmoveto(sqRect.origin.x, sqRect.origin.y);   // display the drawing
  42.     for(i = 0; i<12; i++){
  43.         PSrlineto(length, 0.0);
  44.         PSrlineto(0.0, 8*length);
  45.         PSrlineto(length, 0.0);
  46.         PSrlineto(0.0, -8*length);
  47.     }
  48.     PSstroke();
  49.  
  50.     return self;
  51. }
  52.  
  53. - mouseDownAction:(NXPoint *)currentLocation
  54. {    
  55.     [self mouseDraggedAction:currentLocation];  //now do same as when dragging
  56.     return self;
  57. }
  58.  
  59. - mouseDraggedAction:(NXPoint *)currentLocation
  60. {
  61.     xOffset = sqRect.size.width/2;        // set the offsets for movement wrt the center
  62.     yOffset = sqRect.size.height/2;
  63.     sqRect.origin.x  = currentLocation->x - xOffset;  // new x and y locations are center
  64.     sqRect.origin.y  = currentLocation->y - yOffset;  // of drawing
  65.     [self display];
  66.     return self;
  67. }
  68.  
  69. @end
  70.